﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.IO;

namespace MacroLoaderAddin.MacroAddIn
{
    /// <summary>
    /// Interaction logic for TDivideAddInUIConfig.xaml
    /// </summary>
    public partial class MacroAddInUIConfig : UserControl
    {
        private MacroAddIn _base;

        public MacroAddInUIConfig(MacroAddIn addin)
        {
            InitializeComponent();
            _base = addin;
        }

        private OpenFileDialog _opener;

        /// <summary>
        /// They want to load up a .C or similar ROOT file into the interpreter. Let them set it. :-)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BrowseButton_Click(object sender, RoutedEventArgs e)
        {
            if (_opener == null)
            {
                _opener = new OpenFileDialog();
                _opener.AddExtension = true;
                _opener.CheckFileExists = true;
                _opener.CheckPathExists = true;
                _opener.DefaultExt = ".C";
                _opener.Filter = "C Files|*.C|CPP Files|*.cpp|All Files|*.*";
                _opener.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                _opener.Multiselect = false;
                _opener.Title = "Choose macro to load into ROOT's CINT interpreter";
            }

            if (_base.MacroFilename != null && _base.MacroFilename.Length != 0)
            {
                FileInfo f = new FileInfo(_base.MacroFilename);
                if (f.DirectoryName.Length != 0)
                {
                    _opener.InitialDirectory = f.DirectoryName;
                }
            }

            if (_opener.ShowDialog().Value)
            {
                _base.MacroFilename = _opener.FileName;
            }
        }
    }
}
